/*
 * @Author: your name
 * @Date: 2020-10-03 09:57:01
 * @LastEditTime: 2020-10-04 15:49:53
 * @LastEditors: your name
 * @Description: In User Settings Edit
 * @FilePath: \woniutaofang\lib\routers\routers.dart
 */
import 'package:fluro/fluro.dart';
import 'package:flutter/material.dart' hide Router;
import 'package:woniutaofang/pages/find/find_router.dart';
import 'package:woniutaofang/pages/home/home_router.dart';
import 'package:woniutaofang/pages/index_page.dart';
import 'package:woniutaofang/pages/mine/mine_router.dart';
import 'package:woniutaofang/pages/news/news_router.dart';
import 'package:woniutaofang/routers/router_init.dart';

// ignore: avoid_classes_with_only_static_members
class Routes {
  static String indexPage = '/indexPage';
  static String webViewPage = '/webview';

  static final List<IRouterProvider> _listRouter = [];

  static void configureRoutes(Router router) {
    /// 指定路由跳转错误返回页
    router.notFoundHandler = Handler(
        // ignore: missing_return
        handlerFunc: (BuildContext context, Map<String, List<String>> params) {
      debugPrint('未找到目标页');
      // return PageNotFound();
    });

    router.define(
      indexPage,
      handler: Handler(
        handlerFunc: (BuildContext context, Map<String, List<String>> params) =>
            IndexPage(),
      ),
    );

    // ignore: missing_return
    router.define(webViewPage, handler: Handler(handlerFunc: (_, params) {
      final String title = params['title']?.first;
      final String url = params['url']?.first;
      // return WebViewPage(title: title, url: url);
    }));

    _listRouter.clear();

    /// 各自路由由各自模块管理，统一在此添加初始化
    _listRouter.add(HomeRouter());
    /// 首页
    _listRouter.add(MineRouter());
    /// 我的
    _listRouter.add(NewsRouter());
    /// 消息
    _listRouter.add(FindRouter());
    /// 发现
    /// 初始化路由
    _listRouter.forEach((routerProvider) {
      routerProvider.initRouter(router);
    });
  }
}
